package cn.lds.j368.dsedu.controller;

import cn.lds.j368.dsedu.dto.ResultJson;
import cn.lds.j368.dsedu.entity.Order;
import cn.lds.j368.dsedu.entity.Video;
import cn.lds.j368.dsedu.exceipeion.SysException;
import cn.lds.j368.dsedu.service.NewVideoService;
import cn.lds.j368.dsedu.service.OrderSerivce;
import cn.lds.j368.dsedu.service.VideoService;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/order")
public class OrderController {

    @Autowired
    private OrderSerivce orderSerivce;

    @Autowired
    private VideoService videoService;

    @Autowired
    private NewVideoService newVideoService;

    private Logger log = LoggerFactory.getLogger(OrderController.class);

    @GetMapping("/list")
    public ResultJson<List<Order>> showOrder() throws SysException {
        ResultJson<List<Order>> listResultJson = orderSerivce.selectOrderAll();
        return listResultJson;
    }

    @GetMapping("/video/{videoId}")
    public ResultJson<Video> showOrderVideoByVideoId(@PathVariable Integer videoId){
        return videoService.selectVideoById(videoId);
    }

    @GetMapping("/video2/{videoId}")
    public ResultJson<Video> showOrderVideoByVideoId2(@PathVariable Integer videoId){

        String videoResultJson = newVideoService.selectVideoByVideoId(videoId);

//        log.info("o-data:{}",videoResultJson);

        ResultJson<Video> resultJson = JSON.parseObject(videoResultJson, ResultJson.class);


        return resultJson;
    }

    @PostMapping("/add")
    public ResultJson addOrder(@RequestBody Order order) throws SysException {
        return orderSerivce.addOrder(order);
    }
}
